package api

import (
	"gateway/basic/config"
	__ "gateway/basic/proto"
	"gateway/handler/request"
	"gateway/handler/resp"
	"github.com/gin-gonic/gin"
)

func Search(c *gin.Context) {
	//接收参数
	var req request.Search
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	cleaner, err := config.ClearClient.CleanerSearch(c, &__.CleanerSearchReq{CleanerType: req.CleanerType})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, cleaner)
}

func ToOrder(c *gin.Context) {
	//接收参数
	var req request.ToOrder
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	order, err := config.ClearClient.CleanerAdd(c, &__.CleanerAddReq{
		CleanerId: req.CleanerId,
		OrderId:   req.OrderId,
	})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, order)

}

func NoOrder(c *gin.Context) {
	//接收参数
	var req request.ToOrder
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	order, err := config.ClearClient.CleanerRemove(c, &__.CleanerRemoveReq{
		CleanerId: req.CleanerId,
		OrderId:   req.OrderId,
	})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, order)
}

func MobileUser(c *gin.Context) {
	//接收参数
	var req request.Mobile
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数接收错误", err.Error())
		return
	}
	//业务逻辑
	data, err := config.ClearClient.UserMobile(c, &__.UserMobileReq{
		OrderId: req.OrderId,
		Mobile:  req.Mobile,
	})
	if err != nil {
		resp.Error(c, 400, "服务层错误", err.Error())
		return
	}
	resp.Success(c, data)
}

func EndOrder(c *gin.Context) {

}
